package com.muhuahealth.service.impl;

import com.muhuahealth.dao.EventRecordDao;
import com.muhuahealth.dao.RecordTypeDao;
import com.muhuahealth.entity.EventRecordEntity;
import com.muhuahealth.entity.RecordTypeEntity;
import com.muhuahealth.service.EventRecordService;
import com.muhuahealth.utils.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @author GSK
 * @version 1.0
 * @date 2021/4/13 20:15
 */
@Service
public class EventRecordImpl implements EventRecordService {

    @Autowired
    EventRecordDao eventRecordDao;

    @Autowired
    RecordTypeDao recordTypeDao;

    @Override
    public String addNewEventRecord(EventRecordEntity eventEntity) {

        Integer count = eventRecordDao.addNewEventRecord(eventEntity);
        if(count > 0){
            return "添加成功！";
        }
        return "添加失败";
    }

    @Override
    public Integer getRecordTypeByCondition(Object obj) {

        return eventRecordDao.getRecordTypeByCondition(obj);
    }

    @Override
    public List<EventRecordEntity> searchRecordInfo(EventRecordEntity eventEntity) {

        List<EventRecordEntity> list = eventRecordDao.searchRecordInfo(eventEntity);
        return list;
    }

    @Override
    public void exportExcel(List<String> list, HttpServletResponse response) {

        List<List<String>> dataList = new ArrayList<>();
        if(list == null || list.size() == 0){
            dataList = eventRecordDao.findAllObj();
        }else {
            dataList = eventRecordDao.findByIds(list);
        }

        List<String> titleList = Arrays.asList("序号","事件类型","事件名称","发生时间","发生街道","责任单位");
        ExcelUtil.exportInfo(response,"事件记录信息.xlsx",titleList,dataList);
    }

    @Override
    public List<RecordTypeEntity> exportExcel2() {

        return recordTypeDao.exportExcel2();
    }

}
